<?php
session_start();

define('_HOST',"localhost");
define('_USER',"ROOT");
define('_PWD',"");
define('_DATABASE',"holo");
define('_DSNAME',"http://localhost/holo-webapp-src");

define('_PATHDIRDATA', "../../data/");

include_once("MySqlClass.php");

//utilsateur identifié ? oui -> continue le script, sinon on essaye le login et on renvoie les données de l'utilisateur sinon on redirige 	
	if (! isset($_SESSION['login'])){
		
		//essaye de connecté l'utilisateur
		if((isset($_POST['email'])) && (isset($_POST['pwd']))){
			$mySqlDB = new MySqlClass(_HOST, _USER, _PWD, _DATABASE);
	        $queryRes = $mySqlDB->MysqlSelect("user", "id, type, status, email, pwd, name, activity, phone, web_site_url, adress_text, country, city, zip_code", 
									                  'WHERE email="'.$_POST['email'].'" AND pwd="'.$_POST['pwd'].'"');
	   		 if (count($queryRes) > 0){
	   		 	$_SESSION['login'] = 'true';
	   		  echo '{
                                   "success":true,
    				   "msg":"success",
				    "data":'.json_encode($queryRes).
				  '}';	
	   		 }else{
	   		 
	   		 echo '{
    			      "success":false,
    				   "msg":"wrong user or pass word",
					   "data":'.json_encode($queryRes).
				  '}';
				
			}
			  
			return 0;
			
		}else{
			//reinitailise l'appli
			echo 'non connecté';
			//header('Location: '._DSNAME.'/index.php');   
			return 0;
		}
	}
?>